package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmInvoice;
import cn.powerone.scm.service.IScmInvoiceService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 发票Controller
 * 
 * @author PowerOne
 * @date 2025-08-22
 */
@RestController
@RequestMapping("/scm/scmInvoice")
public class ScmInvoiceController extends BaseController
{
    @Autowired
    private IScmInvoiceService scmInvoiceService;

    /**
     * 查询发票列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmInvoice scmInvoice)
    {
        startPage();
        List<ScmInvoice> list = scmInvoiceService.selectScmInvoiceList(scmInvoice);
        return getDataTable(list);
    }

    /**
     * 导出发票列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:export')")
    @Log(title = "发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmInvoice scmInvoice)
    {
        List<ScmInvoice> list = scmInvoiceService.selectScmInvoiceList(scmInvoice);
        ExcelUtil<ScmInvoice> util = new ExcelUtil<ScmInvoice>(ScmInvoice.class);
        util.exportExcel(response, list, "发票数据");
    }

    /**
     * 获取发票详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmInvoiceService.selectScmInvoiceById(id));
    }

    /**
     * 新增发票
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:add')")
    @Log(title = "发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmInvoice scmInvoice)
    {
        return toAjax(scmInvoiceService.insertScmInvoice(scmInvoice));
    }

    /**
     * 修改发票
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:edit')")
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmInvoice scmInvoice)
    {
        return toAjax(scmInvoiceService.updateScmInvoice(scmInvoice));
    }

    /**
     * 删除发票
     */
    @PreAuthorize("@ss.hasPermi('scm:scmInvoice:remove')")
    @Log(title = "发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmInvoiceService.deleteScmInvoiceByIds(ids));
    }
}
